<?php
/**
 * Created by PhpStorm.
 * User: vbolshov
 * Date: 21.10.2010
 * Time: 15:26:16
 *
 * Null-object design pattern. This Select object always returns empty PDOStatement when performing query(),
 * and zero when performing count()
 *
 */

namespace km\db;

use \IteratorAggregate;
use \Countable;
use \PDOStatement;
use km\util\Pager;

class NullSelect implements IteratorAggregate, Countable {

	/**
	 * @return Select
	 */
	function from($from)
	{
		return $this;
	}
	/**
	 * @return Select
	 */
	function cols($cols, $mode = self::MODE_APPEND)
	{
		return $this;
	}
	/**
	 * @return Select
	 */
	function setCols($cols)
	{
		return $this;
	}
	/**
	 * @return Select
	 */
	function appendCols($cols)
	{
		$this->cols = array_merge($this->cols, (array) $cols);
		return $this;
	}
	/**
	 * @param int $mode
	 * @param mixed $opt1, $opt2,..
	 * @return Select
	 */
	function setFetchMode($mode, $opts = null)
	{
		return $this;
	}

	/**
	 * @return Select
	 */
	function paginate($page_number, $page_size)
	{
		return $this;
	}
	/**
	 * @return Select
	 */
	function limit($limit, $offset = 0)
	{
		return $this;
	}
	/**
	 * @return Select $this
	 */
	function limitByPager(Pager $p)
	{
		return $this;
	}
	/**
	 * @return Select
	 */
	function join($sql, $cols = null, $bind = array())
	{
		return $this;
	}
	/**
	 * @return Select
	 */
	function where($sql)
	{
		return $this;
	}
	/**
	 * @return Select
	 */
	function ifWhere($condition, $sql)
	{
		return $this;
	}
	/**
	 * @return Select
	 */
	function group($expression)
	{
		return $this;
	}
	/**
	 * @return Select
	 */
	function having($expression)
	{
		return $this;
	}
	/**
	 * @return Select
	 */
	function order($expression)
	{
		return $this;
	}
	/**
	 * @return Select
	 */
	function resetOrder()
	{
		return $this;
	}

	/**
	 * @return PDOStatement
	 */
	function query($fetch_mode = null)
	{
		return new PDOStatement();
	}
	/**
	 * Fetch the very first row
	 *
	 * @param int $fetch_mode
	 * @return ActiveRecord | mixed (depends on fetch_mode)
	 */
	function fetchOne($fetch_mode = null)
	{
		return false;
	}
	/**
	 * @param int $fetch_mode
	 */
	function fetchAll($fetch_mode = null)
	{
		return array();
	}

	/**
	 * @return int
	 */
	function count($expression = "*")
	{
		return 0;
	}
	/**
	 * @return string[]
	 */
	function getErrors()
	{
		return array();
	}

	/**
	 * @implements IteratorAggregate
	 * @return Iterator
	 */
	function getIterator()
	{
		return new ArrayObject(array());
	}
	/**
	 * @return string
	 */
	function __toString()
	{
		return "";
	}
}
